package com.xianbeiying.app.ckgl.photo.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xianbeiying.app.ckgl.MyApplication;
import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.UrlBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by donglua on 15/6/21.
 */
public class HistoryPhotoPagerAdapter extends PagerAdapter {

    private List<String> paths = new ArrayList<>();
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private List<String> time;
    public HistoryPhotoPagerAdapter(Context mContext, List<String> paths,List<String> time) {
        this.mContext = mContext;
        this.paths = paths;
        this.time=time;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View itemView = mLayoutInflater.inflate(R.layout.item_hoisty_pager, container, false);
        ImageView imageView = (ImageView) itemView.findViewById(R.id.iv_pager);
        TextView tv_time=(TextView) itemView.findViewById(R.id.time);
        tv_time.setText(time.get(position));
//        Glide.with(mContext)
//        .load("http://"+ MyApplication.IP+ UrlBean.IMAGES+paths.get(position))
//        .thumbnail(0.4f)
//        .placeholder(R.drawable.ic_photo_black_48dp)
//        .error(R.drawable.ic_broken_image_black_48dp)
//        .into(imageView);
        ImageLoader.getInstance().displayImage("http://"+ MyApplication.IP+ UrlBean.IMAGES+paths.get(position),imageView);
//
//        Bitmap bitmap=ImageLoader.getInstance().loadImageSync("http://"+ MyApplication.IP+ UrlBean.IMAGES+paths.get(position));
//        imageView.setImageBitmap(ImageUtil.drawTextToRightBottom(mContext,bitmap,time.get(position),16, Color.GREEN,5,5));
//        imageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (mContext instanceof PhotoPickerActivity) {
//                    if (!((PhotoPickerActivity) mContext).isFinishing()) {
//                        ((PhotoPickerActivity) mContext).onBackPressed();
//                    }
//                }
//            }
//        });

        container.addView(itemView);

        return itemView;
    }


    @Override
    public int getCount() {
        return paths.size();
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }


}
